/*
 * BanBu_CollectionCell
 * @description 本文件提供我收藏的表情界面的定制cell
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供我收藏的表情界面的定制cell
 */

#import "BanBu_CollectionCell.h"
#import "BanBu_SmileViewAPI.h"
#import "AppCommunicationManager.h"
#import "AppDataManager.h"
#import "UIImageView+WebCache.h"

@implementation BanBu_CollectionCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _forthEmo.index = 101;
        _secondEmo.index= 102;
        _thirdEmo.index = 103;
        _forthEmo.index = 104;
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    [_firstEmo release];
    [_secondEmo release];
    [_thirdEmo release];
    [_forthEmo release];
    [_firstSelectView release];
    [_secondSelectView release];
    [_thirdSelectView release];
    [_forthSelectView release];
    [super dealloc];
}

//查看大图,大图可能是动态图，也可能是静态图
-(void)showBigImage:(BanBu_CollectionImageView *)collectView
{
    
}

//设置详细信息
-(void)setAllInfo:(NSDictionary *)collectEmoDic
{
    [_firstEmo setImageInfo:[collectEmoDic valueForKey:@"1"]];
    _firstEmo.delegate = self;
    _firstEmo.index = 1;
    
    if ([collectEmoDic valueForKey:@"2"])
    {
        [_secondEmo setImageInfo:[collectEmoDic valueForKey:@"2"]];
        _secondEmo.delegate = self;
        _secondEmo.index = 2;
        UIImageView * imageView = (UIImageView *)[self viewWithTag:202];
        imageView.hidden = NO;
//        imageView.layer.cornerRadius = 12;
//        imageView.layer.masksToBounds = YES;
    }
    else
    {
        [_secondEmo setImageInfo:nil];
        UIImageView * imageView = (UIImageView *)[self viewWithTag:202];
        imageView.hidden = YES;
//        imageView.layer.cornerRadius = 12;
//        imageView.layer.masksToBounds = YES;
    }
    
    if ([collectEmoDic valueForKey:@"3"])
    {
        [_thirdEmo setImageInfo:[collectEmoDic valueForKey:@"3"]];
        _thirdEmo.delegate = self;
        _thirdEmo.index = 3;
        UIImageView * imageView = (UIImageView *)[self viewWithTag:203];
        imageView.hidden = NO;
//        imageView.layer.cornerRadius = 12;
//        imageView.layer.masksToBounds = YES;
    }
    else
    {
        [_thirdEmo setImageInfo:nil];
        UIImageView * imageView = (UIImageView *)[self viewWithTag:203];
        imageView.hidden = YES;
    }
    
    if ([collectEmoDic valueForKey:@"4"])
    {
        [_forthEmo setImageInfo:[collectEmoDic valueForKey:@"4"]];
        _forthEmo.delegate = self;
        _forthEmo.index = 4;
        UIImageView * imageView = (UIImageView *)[self viewWithTag:204];
        imageView.hidden = NO;
//        imageView.layer.cornerRadius = 12;
//        imageView.layer.masksToBounds = YES;
    }
    else
    {
        [_forthEmo setImageInfo:nil];
        UIImageView * imageView = (UIImageView *)[self viewWithTag:204];
        imageView.hidden = YES;
    }
}

//设置是否选中
-(void)setSelectedOrNot:(NSDictionary *)infoDic
{
    if ([[infoDic valueForKey:[_firstEmo.imageInfoDic valueForKey:KeyFavid]] boolValue])
    {
        _firstSelectView.hidden = NO;
    }
    else
    {
        _firstSelectView.hidden = YES;
    }
    _firstSelectView.tag = 1;
    
    if ([[infoDic valueForKey:[_secondEmo.imageInfoDic valueForKey:KeyFavid]] boolValue])
    {
        _secondSelectView.hidden = NO;
    }
    else
    {
        _secondSelectView.hidden = YES;
    }
    
    _secondSelectView.tag = 2;
    
    if ([[infoDic valueForKey:[_thirdEmo.imageInfoDic valueForKey:KeyFavid]] boolValue])
    {
        _thirdSelectView.hidden = NO;
    }
    else
    {
        _thirdSelectView.hidden = YES;
    }
    _thirdSelectView.tag = 3;
    
    if ([[infoDic valueForKey:[_forthEmo.imageInfoDic valueForKey:KeyFavid]] boolValue])
    {
        _forthSelectView.hidden = NO;
    }
    else
    {
        _forthSelectView.hidden = YES;
    }
    _forthSelectView.tag = 4;
}

-(void)setSelectedView:(BanBu_CollectionImageView *)collectView
{
    if (self.delegate || [self.delegate respondsToSelector:@selector(setSelectedView: withCell:)])
    {
        [self.delegate setSelectedView:collectView withCell:self];
    }
}

-(void)addCollectedEmo:(BanBu_CollectionImageView *)collectView
{
    if (self.delegate || [self.delegate respondsToSelector:@selector(setSelectedView: withCell:)])
    {
        [self.delegate addCollectedEmo:collectView];
    }
}

-(void)setAddButtonViewHidden:(BanBu_CollectionImageView *)collectView withBool:(BOOL)hidden
{
    int index = collectView.index;
    
    switch (index)
    {
        case 1:
        {
            _firstEmo.hidden = hidden;
            UIImageView * imageBg = (UIImageView *)[self viewWithTag:201];
            imageBg.hidden = hidden;
        }
            break;
        case 2:
        {
            _secondEmo.hidden = hidden;
            UIImageView * imageBg = (UIImageView *)[self viewWithTag:202];
            imageBg.hidden = hidden;
        }
            break;
        case 3:
        {
            _thirdEmo.hidden = hidden;
            UIImageView * imageBg = (UIImageView *)[self viewWithTag:203];
            imageBg.hidden = hidden;
        }
            break;
        case 4:
        {
            _forthEmo.hidden = hidden;
            UIImageView * imageBg = (UIImageView *)[self viewWithTag:204];
            imageBg.hidden = hidden;
        }
            break;
        default:
            break;
    }
}

-(BOOL)getIsEditing
{
    if ([self.delegate respondsToSelector:@selector(isEditing)])
    {
        BOOL editing = [self.delegate isEditing];
        if (editing)
        {
            return YES;
        }
        return NO;
    }
}

@end
